package csce315.group10.androidapp;

import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

import com.dropbox.client2.DropboxAPI;
import com.dropbox.client2.android.AndroidAuthSession;
import com.dropbox.client2.session.AccessTokenPair;
import com.dropbox.client2.session.AppKeyPair;
import com.dropbox.client2.session.Session.AccessType;

import android.app.Application;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;


public class Topic implements Parcelable {
	@ElementList(name = "messages",required = false)
	ArrayList<Message> messages;
	
	private String author;
	private String topic;
	public Topic(@Attribute(name = "topic_name")String _topic_name,@Element(name = "author") String _author_name){
		topic = _topic_name;
		author = _author_name;
		messages = new ArrayList<Message>();

	}
	/* constructor used by Parcelable */
	public Topic(Parcel source){
        /*
         * Reconstruct from the Parcel
         */
        topic = source.readString();
        author = source.readString();
        source.readTypedList(messages,Message.CREATOR);

	}
	/* used in serialization to pass in an intent */
	public int describeContents() {
		return hashCode();
	}
	/* used to serialize data to pass in an intent*/
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(topic);
	    dest.writeString(author);
	    dest.writeTypedList(messages);

	}
	/* used to create an event object from Parcelable */
	public static final Parcelable.Creator CREATOR =
    	new Parcelable.Creator() {
            public Topic createFromParcel(Parcel in) {
                return new Topic(in);
            }
 
            public Topic[] newArray(int size) {
                return new Topic[size];
            }
        };
	
	
	@Attribute(name ="topic_name")
	public String get_topic(){
		return topic;
	}
	
	@Element(name="author")
	public String get_author(){		
		return author;
	}

	public ArrayList<Message> getMessages(){
		return messages;
	}
	
	public void setMessages(ArrayList<Message> _messages){
		messages = _messages;
	}
}
